class Solution:
    def longestValidParentheses(self, s: str):
        i, res, mid_res = 0, 0, 0
        while (('(' + '_' * i + ')') in s) or i < len(s):
            s = s.replace('(' + '_' * i + ')', ('_' * (i + 2)))
            i += 2
        for j in s:
            if j == "_":
                mid_res += 1
            else:
                mid_res = 0
            res = max(res, mid_res)
        return res


a = Solution()
print(a.longestValidParentheses("()(()"))
